<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'login.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="qczlm/css/login2.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="qczlm/js/jquery-1.10.2.min.js"></script>
	<script type="text/javascript" src="qczlm/js/login.js"></script>
	<style>
		.tcode{
			background:#FFF1E8;
			border:1px solid #FF751A;
			color:#FF6A00;
			height:34px;
			width:120px;
			border-radius:3px;
			cursor:pointer;
		}
	</style>
  </head>
  
  <body>
  	<h1>千城智联云平台登录<sup>V1.0</sup></h1>
    <div class="login" style="margin-top:50px;">
    <div class="header">
        <div class="switch" id="switch"><a class="switch_btn_focus" id="switch_qlogin" href="javascript:void(0);" tabindex="7">快速登录</a>
			<a class="switch_btn" id="switch_login" href="javascript:void(0);" tabindex="8">快速注册</a><div class="switch_bottom" id="switch_bottom" style="position: absolute; width: 64px; left: 0px;"></div>
        </div>
    </div>    
    <div class="web_qr_login" id="web_qr_login" style="display: block; height: 235px;">    
            <!--登录-->
            <div class="web_login" id="web_login">
               <div class="login-box">
			<div class="login_form">
				<form action="mexamine/login_user" name="myform" method="post">
                <div class="uinArea" id="uinArea">
                <label class="input-tips" for="u">帐号：</label>
                <div class="inputOuter" id="uArea">
                    <input type="text" id="login_phone" name="phone" class="inputstyle"/>
                </div>
                </div>
                <div class="pwdArea" id="pwdArea">
               <label class="input-tips" for="p">密码：</label> 
               <div class="inputOuter" id="pArea">
                    <input type="password" id="login_password" name="password" class="inputstyle"/>
                </div>
                </div>
                <input type="radio" name="utype" value="1" checked>普通用户
  				<input type="radio" name="utype" value="0" >管理员
                <div style="padding-left:50px;margin-top:20px;">
                	<input type="button" onclick="login();" id="btn" value="登 录" style="width:150px;" class="button_blue"/>
                </div>
              </form>
           </div>
            	</div>
            </div>
            <!--登录end-->
  </div>
  <!--注册-->
    <div class="qlogin" id="qlogin" style="display: none; ">
    <div class="web_login">
    	<form name="form2" id="regUser" accept-charset="utf-8"  action="http://www.js-css.cn" method="post">
       		<ul class="reg_form" id="reg-ul">
                <li>
                    <label  class="input-tips2">平台名称：</label>
                    <div class="inputOuter2">
                        <input type="text" id="appname" maxlength="16" class="inputstyle2"/>
                        <div id="appnameText" style="color:red;"></div>
                    </div>
                </li>
                <li>
	                <label class="input-tips2">用户名称：</label>
                    <div class="inputOuter2">
                        <input type="text" id="username" maxlength="16" class="inputstyle2"/>
                    </div>
                </li>
                <li>
                	<label class="input-tips2">手机号码：</label>
                    <div class="inputOuter2">
                        <input type="text" id="phone" maxlength="11" class="inputstyle2" />
                    </div>
                    
                </li>
                <li>
                 	<label class="input-tips2">验证码：</label>
                    <div class="inputOuter2">
                        <input type="text" style="width:65px;height:30px;" id="code" maxlength="4" class="inputstyle2"/>
					    <input class="tcode" type="button" id="gcode" value="获取短信验证码">
                    </div>
                    <div id="codeText"></div>
                </li>
                <li>
                	<label class="input-tips2">输入密码：</label>
                    <div class="inputOuter2">
                        <input type="password" id="new_pd" maxlength="10" class="inputstyle2"/>
                    </div>
                </li>
                <li>
                	<label class="input-tips2">确认密码：</label>
                    <div class="inputOuter2">
                        <input type="password" id="old_pd" maxlength="10" class="inputstyle2"/>
                    </div>
                </li>
                <li>
                    <div id="success" style="text-align: center;color:red;font-size:14px;"></div>
                    <div class="inputArea">
                        <input type="button" id="register" style="margin-top:10px;margin-left:85px;" class="button_blue" value="注册"/>
                    </div>
                </li>
            </ul>
           </form>
    </div>
    </div>
    <!--注册end-->
    
    <!-- js代码 -->
  <script type="text/javascript">
        var countdown=5; 
		function settime(obj) { 
		    if (countdown == 0) { 
		        obj.removeAttribute("disabled");    
		        obj.value="免费获取验证码"; 
		        countdown = 5; 
		        return;
		    } else { 
		        obj.setAttribute("disabled", true); 
		        obj.value="重新发送(" + countdown + ")"; 
		        countdown--; 
		    } 
		setTimeout(function() { 
		    settime(obj) }
		    ,1000) 
		}
  
  		//登录---------------------------------
  		function login(){
  			var login_phone = $("#login_phone").val();
			var login_password = $("#login_password").val();
			var pp=$('input:radio:checked').val();
			if(!login_phone.replace(/\s/g,"")){
				alert("用户名不能为空");
			}else if(!login_password.replace(/\s/g,"")){
				alert("密码不能为空");
			}else{
				document.myform.submit();
			}
  		}
  		
  		//注册-------------------------------
  		$(function(){
			//获取验证码
			$("#gcode").click(function(){
				var phone=$("#phone").val();
				if(!phone.replace(/\s/g,"")){
					alert("手机号码不能为空"+phone);
				}else{
					settime(this);
					$.ajax({
						url:'mexamine/send',
					    type:'get',
					    data:{phone:phone},
					    dataType:'json',
					    success:function(JR){
					    	JR=eval("("+JR+")");
					    	if(JR.success=="true"){
					    	}
					    }
					});
				}
			});
			//检测当前平台是否已经注册
			$("#appname").bind("input propertychange", function(){
				var appname=$("#appname").val();
				if(appname.replace(/\s/g,"")){
					$.ajax({
						url:'branch/checkbranch',
						type:'get',
						data:{appname:appname},
						dataType:'json',
						success:function(JR){
							document.getElementById("appnameText").innerHTML=""+JR.msg;
						}
					});
				}else{
					$("#appnameText").html("");
				}
			});
			//注册
			$("#register").click(function(){
				var code=$("#code").val();		//验证码
				var phone=$("#phone").val();	//手机号码
				var appname=$("#appname").val();//分平台名
				var username=$("#username").val();//用户名
				var new_pd=$("#new_pd").val();
				var old_pd=$("#old_pd").val();
				if(!code.replace(/\s/g,"")){
					alert("验证码不能为空");
				}else if(!phone.replace(/\s/g,"")){
					alert("手机号码不能为空");
				}else if(!appname.replace(/\s/g,"")){
					alert("分平台名称不能为空");
				}else if(!username.replace(/\s/g,"")){
					alert("用户名不能为空");
				}else if(!new_pd.replace(/\s/g,"") && !old_pd.replace(/\s/g,"")){
					alert("密码不能为空");
				}else{
					if(new_pd!=old_pd){
						alert("请确认密码是否一致！");
						return;
					}
					checkcode(phone,code,appname,username,new_pd);
				}
			});
			 //回车提交事件
			/* $("body").keydown(function() {
			    if (event.keyCode == "13") {//keyCode=13是回车键
			       login();
			    }
			});  */ 
		});
		
		//注册方法
		function checkcode(phone,code,appname,username,new_pd){
			$.ajax({
				url:'mexamine/checkcode',
			    type:'post',
			    data:{
			        phone:phone,
			        code:code
			    },
			    dataType:'json',
			    success:function(JR){
			    	if(JR.success==true){
			    		$("#codeText").html("");
			    		$.ajax({
							url:'branch/register',
						    type:'post',
						    data:{
						    	appname:$("#appname").val(),
						    	username:$("#username").val(),
						        phone:phone,
						        password:new_pd
						    },
						    dataType:'json',
						    success:function(JR){
						    	if(JR.success==true){
						    		$("#success").html("注册成功,secret为："+JR.obj["secret"]);
						    		window.location.href="mexamine/success?secret="+JR.obj["secret"]+"&createTime="+JR.obj["createTime"]
						    		+"&id="+JR.obj["id"]+"&appname="+appname;
						    	}else{
						    		$("#success").html("注册失败");
						    	}
						    }
						});
			    	}else{
			    		$("#success").html("");
			    		$("#codeText").html("验证码错误");
			    	}
			    }
			});
		}
  </script>
  </body>
</html>
